package com.im.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.im.app.model.ChatLogs;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ChatLogsMapper extends BaseMapper<ChatLogs> {

    @Delete("delete from chat_logs where (send_id=#{sendId} and recv_id=#{recvId}) OR (send_id=#{recvId} and recv_id=#{sendId})")
    int clearChatLog(@Param("sendId")String opUserId,@Param("recvId")String userId);

    @Update("Update chat_logs set is_read = 1 where send_id=#{sendId} and recv_id=#{recvId}")
    int updateIsRead(@Param("sendId")String sendId, @Param("recvId")String recvId);

    @Delete("delete from chat_logs where msg_id=#{msgId}")
    int withDram(@Param("msgId")String msgId);

    @Select("SELECT * from chat_logs WHERE chat_type = 2 and ((send_id=#{opUserId} and recv_id=#{recvId}) OR (send_id=#{recvId} and recv_id=#{opUserId})) and create_time < #{createTime} order by create_time desc limit 20")
    List<ChatLogs> getChatLogsList(@Param("opUserId")String opUserId,@Param("recvId")String userId,@Param("createTime")Long createTime);

    @Select("SELECT * from chat_logs WHERE chat_type = 1 and recv_id=#{groupId} and create_time < #{createTime} order by create_time desc limit 20")
    List<ChatLogs> getGroupHistoryMessage(@Param("groupId")String groupId,@Param("createTime")Long createTime);

    int getTodayChatLogs(String userId);

    List<ChatLogs> selectChatLogsList(ChatLogs chatLogs);

    int updateChatLogs(ChatLogs chatLogs);

    int updateMsg(String userId,String nickName,String avatar);

}

